<template>
    <div class="param-set-contain">
        <!-- 头部搜索 -->
        <div class="Search_Top_Part">
            <div class="search_list" >
                <div>
                    <div class="input_flex">
						<el-input clearable v-model="queryForm.itemName" placeholder="单位名称"></el-input>
                    </div>
                    <div class="input_flex">
                        <el-select clearable v-model="queryForm.status" placeholder="状态">
                            <el-option label="在用" value="0"></el-option>
                            <el-option label="停用" value="1"></el-option>
                        </el-select>
                    </div>
                </div>
            </div>
            <div class="search_bt">
                <span class="zll-search" @click="getList">搜索</span>
                <span class="zll-search-reset" @click="searchReset()">重置</span>
            </div>
        </div>
        <div class="Search_Top_Input">
            <div class="addNew">
                <span @click="openSure('add',{id:'',itemType:'3'})"  v-if="hasRole('st:basedata:add')"><i class="el-icon-circle-plus-outline" ></i> 新建</span>
                <span class="delete" @click="openSure('batchDel','')" v-if="hasRole('st:basedata:del')"><i class="el-icon-delete"></i> 删除</span>
            </div>
        </div>
        <!-- table -->
        <sys-table
            :isMultipleSelection="true"
            :tableData="tableData"
            :tableLoading="tableLoading"
            :tableHeader="tableHeader"
            :scopeWidth="120"
            @getSelection="getSelection"
			ref="systable"
        >
            <template slot-scope="scope" slot="operate">
                <el-button @click="openSure('edit',scope.row)" type="text" size="small"  v-if="hasRole('st:basedata:edit')">编辑</el-button>
                <el-button type="text" size="small" @click="openSure('del',scope.row)"  v-if="hasRole('st:basedata:del')">删除</el-button>
            </template>
        </sys-table>

        <!-- 新建弹框 -->
        <div class="zll-dialog">
            <popout :title="type=='add'?'计量单位 · 新建':'计量单位 · 编辑'"  :visible.sync="addDialog" v-if="addDialog" class="minSize">
                <Add ref="add" slot="content" @refreshData="refreshData" :type="type" :editData="editData" ></Add>
                <template slot="bottom">
                    <p class="zll-botton Info" @click="addDialog = false">关 闭</p>
                    <p class="zll-botton" @click="()=>{this.$refs.add.setFormData('addForm')}">提 交</p>
                </template>
            </popout>
        </div>
    </div>
</template>

<script>
    import Add from './add'
    export default {
        data(){
            return {
				queryForm:{itemName:'',status:'',itemType:'3'},
				tableLoading: true, //table刷新
				tableData: [],
				tableHeader: [],
				addDialog: false, //弹框
				selectChoice: [],
				type: '',
				openSureData:{type:'',data:''},
				editData:{id:'',itemType:'3'}
            }
        },
        methods: {
			doAction(){
				if(this.openSureData.type =='see'||this.openSureData.type =='edit'||this.openSureData.type =='add'){
					this.edit(this.openSureData.data,this.openSureData.type);
				}else if(this.openSureData.type =='del'){
					this.deleteRow(this.openSureData.data);
				}else if(this.openSureData.type =='batchDel'){
					this.batchDeleteRow();
				}
			},

			openSure(type,row){
				this.openSureData.type = type;
				this.openSureData.data = row;
				this.$parent.openPwdDialog('base1');
			},


			getList() {
				let self = this;
				this.tableLoading = true;
				this.tableData = [];
				self.$refs.systable.resetPage();
				self.$http({
					url: "/jinl/sysItem/getMgItemList",
					method: "post",
					params:self.queryForm
				}).then(resp => {
					if (resp.success) {	
						self.tableHeader = [
							{"columnValue": "itemName", "columnName": "单位名称" },
							{"columnValue": "userName", "columnName": "创建人" },
							{"columnValue": "createTimeFt", "columnName": "创建日期" },
							{"columnValue": "itemStatusCn", "columnName": "状态" ,refColor:true},
						];
						self.tableData = resp.result;
					}
					this.tableLoading = false;
				});
			},


			deleteRow(row){
				let ids = [row.id];
				this.deleteMethod(ids);
			},

			batchDeleteRow(){
				let ids = [];
				for(let data of this.selectChoice){
					ids.push(data.id);
				}
				this.deleteMethod(ids);
			},

			deleteMethod(ids){
				let self = this;
				let param = {ids:ids};
				if(param.ids.length == 0){
					self.$notify({
						title: '提示',
						message: "至少选择一条记录！",
						type: 'warning'
					});
					return
				}
				self.$confirm('确定删除该信息？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					self.$http({
						url: "/jinl/sysItem/deleteMgItemDetail",
						method: "post",
						data: JSON.stringify(param),
						dataType: 'json',
						contentType: "application/json",
					}).then(resp => {
						if (resp.success) {
							self.getList();
							self.$notify({
								title: '提示',
								message: "删除成功！",
								type: 'success'
							});
							return
						}
						self.$notify({
							title: '提示',
							message: "操作失败，请联系管理员！",
							type: 'error'
						});
					});
				});
			},

			edit(data, type) { //管理
				let self = this;
				self.type = type ;
				self.addDialog = true;
				self.$nextTick(() =>{
					self.editData = Object.assign({},data);
				});
			},
			getSelection(val) {
				this.selectChoice = val;
			},
			searchReset() { //重置搜索
				this.queryForm = {itemName:'',status:'',itemType:'3'};
				this.getList();
			},

			refreshData(){
				this.addDialog = false;
				this.searchReset();
			},
        },
        mounted(){
            this.getList();//显示table
        },
        components: {
            Add,
        }
    }
</script>

<style lang="scss" scoped>
@import "@/style/SearchTop.scss";
</style>
